<?php

class user extends tsApp{
private $redis_on = 0;//redis是否开启，0不开启，1开启

	public function __construct($db){
 		parent::__construct($db);
	}
	public function caServiceItem( $id ,$cid = 0 ){
		$key = "meifa_service_item:$cid:$id";		
		
		if( $this->redis_on ){
			//R()->delete( $key );
			if( !R()->exists( $key ) ){
			$data = $this->find('service_item',array('item_id'=>$id));  
				R()->hMset( $key,$data );
				R()->expireAt( $key,time()+3600 );
				return $data;
			}
			return R()->hGetAll($key);
		}else{
			$data = $this->find('service_item',array('item_id'=>$id));  
			return $data;
		}
	} 
	public function caHairdresser( $id ,$cid = 0 ){
		$key = "meifa_hairdresser:$cid:$id";				
		if( $this->redis_on ){
			//R()->delete( $key );
			if( !R()->exists( $key ) ){
			$data = $this->find('hairdresser',array('hairdresser_id'=>$id));  
				R()->hMset( $key,$data );
				R()->expireAt( $key,time()+3600 );
				return $data;
			}
			return R()->hGetAll($key);
		}else{
			$data = $this->find('hairdresser',array('hairdresser_id'=>$id));  
			return $data;
		}
	}
	public function getPersonalMoney( $hid = 0 ,$itemId = 0 ,$cid = 0 ){
		$key = "meifa_personal_money:$cid:$hid:$itemId";
		$conStr = '1=1' ;
		if( $hid > 0 ){
			$conStr .= ' and hairdresser_id='.$hid;
		}
		if( $itemId > 0 ){
			$conStr .= ' and item_id='.$itemId;
		}
		if( $this->redis_on ){
			//R()->delete( $key );
			if( !R()->exists( $key ) ){
			$data = $this->find('item_hairdresser_relation',$conStr,'price,fencheng,update_at' );  
				R()->hMset( $key,$data );
				R()->expireAt( $key,time()+3600 );
				return $data;
			}
			return R()->hGetAll($key);
		}else{
			$data = $this->find('item_hairdresser_relation',$conStr,'price,fencheng,update_at' ); // print_r($data);
			return $data;
		}
	}
	//获取是否节假日
	public function isholiday($dt){
		$tm=date('Ymd',$dt);
		$url=$this->holidayapi.$tm;
		$ch = curl_init();
		$header=array('apikey:eed45fd83c2556b83e912e82cc5f5595');
		curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch , CURLOPT_URL , $url);
		$ot = curl_exec($ch);
		return $ot;
	} 
  
 

}
